package com.un.ebs.question.service;

import com.alibaba.fastjson.JSONArray;
import com.un.ebs.businessObject.service.DbService;
import com.un.ebs.core.metadata.ServiceFunctionExt;
import com.un.ebs.core.metadata.ServiceInfoExt;
import com.un.ebs.core.util.WebResult;
import com.un.ebs.core.util.WebUtils;
import com.un.ebs.question.domain.Question;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author liubo
 * @create 2021-06-17 10:45
 */
@Service()
@ServiceInfoExt(value = "bf1302b4330d96df05ed2645c4aaaf5d", functionName = "submit", functionDesc = "提交")
public class QuestionSubmitServiceExt implements ServiceFunctionExt<String, WebResult<List<Question>>> {

    @Autowired
    private DbService dbService;

    @Override
    public WebResult<List<Question>> exec(String arg) {
        JSONArray ary = dbService.list("bf1302b4330d96df05ed2645c4aaaf5d", "create_time", null);
        List<Question> ret = new ArrayList<>();
        for (Object obj : ary) {
            ret.add(convert(obj, Question.class));
        }
        return WebUtils.success(ret);
    }
}
